﻿using System;
using AutoMapper;
using Common.Views;
using Dto.ApiResponses;
using Dto.ApiResponses.TemplateResponses;
using PetaPoco;
using Sanelib.DataView;
using WebApp.Services;

namespace WebApp.ModelService.Impl
{
    public class TempleteModelService : BaseModelService, ITempleteModelService
    {
        private readonly IViewRepository<TempleteView> _templeteViewRepository;
        public TempleteModelService(IUserSession userSession, IMappingEngine mappingEngine, IViewRepository<TempleteView> templeteViewRepository)
            : base(userSession, mappingEngine)
        {
            _templeteViewRepository = templeteViewRepository;
        }

        public PageResponse<TemplateLine> GetPageBySpecification(SearchSpecification specification = null)
        {
            if (specification == null)
            {
                specification = new SearchSpecification
                {
                    ColumnName = "Name",
                    ColumnValue = "%",
                    FilterType = "like"
                };
            }

            var templeteView = _templeteViewRepository.SearchBySpecification(specification, null);
            var response = Mapper.Map<Page<TempleteView>, PageResponse<TemplateLine>>(templeteView);
            return response;
        }      

        public TemplateResponse GetTempleteById(Guid id)
        {
            var templeteView = _templeteViewRepository.GetById(id);
            var response = Mapper.Map<TempleteView, TemplateResponse>(templeteView);
            return response;
        }
    }
}
